home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / OUTXTXY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.7 KB  |  65 lines

  1.  
  2. /* outxtxy---outextxy,p847 */
  3. #include <alloc.h>
  4. #include <graphics.h>
  5. char label [] = "This is a label";
  6. main()
  7. {
  8.     int graphdriver = DETECT, graphmode, xmax, ymax,
  9.                         xsize, ysize, x, y, c;
  10.     void *i_buf;
  11.                 /* Detect and initialize graphics system */
  12.     initgraph(&graphdriver, &graphmode, "c:\\turboc");
  13.             /* Draw a small marker and save it in a buffer */
  14.     lineto<5,0>;
  15.     moveto<0,0>;
  16.     lineto<0,5>;
  17.         /* Allocate buffer -- we skip error checking, but you
  18.                             * shouldn't */
  19.     i_buf = malloc(imagesize(0,0,5,5));
  20.     getimage(0,0,5,5, i_buf);
  21.     cleardevice();
  22.             /* Display instructions for user */
  23.     outtextxy(10, getmaxy()-20,"q = exit, p = place  label, "
  24.                     "h=left, j=down, k=up, l=right");
  25.                 /* Define a viewport */
  26.     xmax = getmaxx();
  27.     ymax = getmaxy();
  28.     xsize = xmax - 100;
  29.     ysize = ymax - 60;
  30.     setviewport(50, 30, xsize+50, ysize+30, 1);
  31.     setfillstyle(SOLID_FILL, RED);
  32.     bar3d(0,0,xsize,ysize,0,1);
  33.     setcolor(YELLOW);
  34.     settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);
  35.     settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  36.                 /* Ask user to position marker and press
  37.                  'p' to place a label or 'q' to quit. */
  38.     x = xsize/2;
  39.     y = ysize/2;
  40.     putimage(x,y,i_buf,XOR_PUT);
  41.     while((c = getch()) != 'q')
  42.     {
  43.                 /*    First erase at last position */
  44.         putimage(x,y,i_buf,XOR_PUT);
  45.         switch(c)
  46.         {
  47.             case 'h': x -= 2; /* 2 pixels left */
  48.                 break;
  49.             case 'l': x += 2; /* 2 pixels right */
  50.                 break;
  51.             case 'j': y += 2; /* 2 pixels down */
  52.                 break;
  53.             case 'k': y -= 2; /* 2 pixels up */
  54.                 break;
  55.             /* If it's 'p' place label using outtextxy */
  56.             case 'p': outtextxy(x,y,label);
  57.                 break;
  58.         }
  59.                 /* Redraw at new position */
  60.         putimage(x,y,i_buf,XOR_PUT);
  61.     }
  62.                 /* Close graphics system when done */
  63.     closegraph();
  64. }
  65.